import moose

class IzhikevichPlus(moose.IzhikevichNrn):
    '''
    This is a basic IzhikevichNrn with its own tables to take care of
        input and output(Vm).  It uses physiological units (ms, mV, etc) 
    '''
    def __init__(self, a=0.02, b=0.2, c=-65.0, d=6.0,
                       initVm=-70.0, name="No name given."):
        """
        Default kwargs correspond to a "tonic firing" neuron.
        """
        moose.IzhikevichNrn.__init__(self, name)

        # set up for physiological units
        self.alpha = 0.04
        self.beta  = 5.0
        self.gamma = 140.0

        # the spike detection threshold
        self.Vmax  = 30.0

        # default values for the parameters of the neuron, this can
        #    be overwritten with self.setParams(a,b,c,d,initVm)
        self.a      = a
        self.b      = b
        self.c      = c
        self.d      = d
        self.initVm = initVm
        
        self.initU  = initVm * b # makes sure dU = 0 for the first time step.

    def setParams(self, a, b, c, d, initVm):
        '''
        Set the adjustable parameters of the model neuron.
        '''
        self.a      = a
        self.b      = b
        self.c      = c
        self.d      = d
        self.initVm = initVm

        self.initU  = initVm * b # makes sure dU = 0 for the first time step.

    def setupTables(self):
        """
        Sets up tables to be used as the input and output for the neuron
        """
        self.VmTable = moose.Table("VmTable", self)
        self.VmTable.stepMode = 3 # FIXME what does stepMode do??!

        self.injectTable = moose.Table("injectTable", self)
        self.injectTable.stepMode = 3

        self.inputTable = moose.Table("inputTable", self)
        self.inputTable.stepMode = 1 # TAB_LOOP (FIXME whatever that means)

        # connections
        self.connect("Vm", self.VmTable, "inputRequest")
        self.inputTable.connect("outputSrc", self,             "injectDest")
        self.inputTable.connect("output"   , self.injectTable, "inputRequest") 
        
    def setInputTable(self, inputArray, dt):
        '''
        Specify the current input to the model.
        '''
        self.inputTable.xmin     = 0
        self.inputTable.xmax     = dt * len(inputArray)
        self.inputTable.stepSize = dt
        self.inputTable.xdivs    = len(inputArray)
        for i in xrange(len(inputArray)):
            self.inputTable[i] = inputArray[i]
